#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <fstream>
#include "Splines.h"
#define PI acos(-1)

using namespace std;

int main(int argc, char* argv[]) {
    int n;  // 定义插值点数量
    vector<double> T, xCoords, yCoords;  // 定义时间点和x、y坐标的容器

    n = 10;
    // 计算每个时间点和对应的x、y坐标
    for (int i = 0; i <= n; i++) {
        T.push_back(2.0 * PI * i / n - PI / 2);
    }
    for (int i = 0; i <= n; i++) {
        xCoords.push_back(sqrt(3) * cos(T[i]));
        yCoords.push_back(sqrt(3) * (2.0 / 3.0) * sin(T[i]) + (2.0 / 3.0) * sqrt(abs(xCoords[i])));
    }

    // 创建样条插值对象
    ppForm splineX(T, xCoords);
    ppForm splineY(T, yCoords);

    // 输出数据至E.txt
    ofstream E("QE.txt");

    // 对x坐标进行样条插值并写入文件
    for (double xx = -0.5 * PI; xx <= 1.5 * PI; xx += 0.01) {
        E << splineX.S3(3, 0, 0, xx) << " ";
    }
    E << endl;

    // 对y坐标进行样条插值并写入文件
    for (double xx = -0.5 * PI; xx <= 1.5 * PI; xx += 0.01) {
        E << splineY.S3(3, 0, 0, xx) << " ";
    }
    E << endl;

    E.close();
    cout << "Interpolations saved to E.txt" << endl;

    return 0;
}
